package com.rongshu.sendmessage.util.itemDecoration;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public class MyItemDecoration extends RecyclerView.ItemDecoration {
    private int left;
    private int bottom;

    public MyItemDecoration() {
        this.left=20;
        this.bottom=10;
    }
    public MyItemDecoration(int left, int bottom) {
        this.left=left;
        this.bottom=bottom;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        //不是第一个的格子都设一个左边和底部的间距
        outRect.left = left;
        outRect.bottom = bottom;
        //由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
//        int position=parent.getChildLayoutPosition(view);
//        if (position%3==0) {
//            outRect.left = 0;
//        }
//
//        int itemCount=parent.getAdapter().getItemCount();
//        int rowCount=itemCount%3==0?itemCount/3:itemCount/3+1;     //一共几行
//        int currRowCount=position%3==0?position/3+1:position/3+1;  //当前第几行
//
//        //当前是最后一行的话底部没有间距
//        if(currRowCount==rowCount){
//            outRect.bottom = 10;
//        }
//        System.out.println();
    }
}
